/* -*- coding: utf-8; tab-width: 4 -*-
vim: ts=4 noet ai */

/**
	Hide Preferences for Firefox

	Copyright © 2016  Desktopd Project

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

	@license GPL-3.0+
	@file
*/

'use strict';

const _$prefs = require ('sdk/simple-prefs');

// Get a snapshot of add-on preferences
exports.getBranch = aName => {
	const $prefs = _$prefs.prefs;
	
	const branch = Object.create (null);
	const name = aName + '.';
	const len = name.length;
	
	Object.getOwnPropertyNames ($prefs)
		.filter (i => name === i.substr (0, len))
		.forEach (i => void (branch[i.substr (len)] = $prefs[i]));
	return Object.freeze (branch);
};

exports.listen = (name, handler) => _$prefs.on (name, handler);

